<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8" />
    <title>添加</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"
    />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all" />
    <script src="/layuiadmin/layui/layui.js"></script>
  </head>
  <body style="background-color: #fff">
    <div class="layui-card">
      <div class="layui-card-body">
        <form
          class="layui-form"
          action=""
          class="layui-form layui-form-pane"
          lay-filter="layui-form-pane"
          id="sbumitForm"
        >
          <div class="layui-form-item">
            <label class="layui-form-label">回放标题</label>
            <div class="layui-input-block">
              <input
                type="text"
                name="title"
                value="{$model->title}"
                lay-verify="required"
                id="input_title"
                class="layui-input"
                placeholder="回放标题"
                autocomplete="off"
              />
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">回放类型</label>
            <div class="layui-input-block">
              <select
                name="replay_category"
                lay-filter="category"
                lay-verify="required"
              >
                <option value="">请选择</option>
                <?php foreach($replay_categorys as $key =>
                $value) {?>
                <option value="{$key}" <?php if(isset($parent_category->
                  id) && $parent_category-> id == $key){echo 'selected';}
                  ?>>{$value}
                </option>
                <?php }?>
              </select>
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">二级类型</label>
            <div class="layui-input-block">
              <select
                name="child_category"
                id="child_category"
                lay-verify="required"
              >
                <option value="">请选择类目</option>
                <?php foreach($child_categorys as $key =>
                $value) {?>
                <option value="{$key}" <?php if($model->
                  replay_category == $key){echo 'selected';} ?>>{$value}
                </option>
                <?php }?>
              </select>
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">回放地址</label>
            <div class="layui-input-block">
              <input type="text" name="down_url"
              <?php
                if ($model['down_url']!='' && substr_count($model['down_url'], 'http') == 0) {
                  echo 'disabled';
                }
              ?>
              value="{$model->down_url}" class="layui-input"
              placeholder="回放地址" autocomplete="off" />
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">m3u8地址</label>
            <div class="layui-input-block">
              <input type="text" name="play_url"
              <?php
                if ($model['play_url']!='' && substr_count($model['play_url'], 'http') == 0) {
                  echo 'disabled';
                }
              ?>
              value="{$model->play_url}" class="layui-input"
              placeholder="m3u8地址" autocomplete="off" />
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">横/竖 屏</label>
            <div class="layui-input-block">
              <input type="radio" value="1" name="direction" title="竖屏" {eq
              name="$model->direction" value="1" }checked{/eq} /> <input
              type="radio" value="0" name="direction" title="横屏" {eq
              name="$model->direction" value="0" }checked{/eq} />
            </div>
          </div>

          <div class="layui-form-item" style="margin-top: 35px">
            <div class="layui-input-block">
              <span
                class="layui-btn"
                lay-submit=""
                lay-filter="submitForm"
                style="width: 100%"
                >确认修改</span
              >
            </div>
          </div>
        </form>
      </div>
    </div>

    <script>
      layui.use(["form"], function () {
        $ = layui.jquery;
        var form = layui.form,
          layer = layui.layer;
        //监听一级类型
        form.on("select(category)", function (data) {
          let select = $("#child_category");
          let category_id = data.value;

          // 下拉选择置空
          select.empty();
          form.render("select");

          if (category_id > 0) {
            $.ajax({
              url: "/admin/video/repay_child_category",
              type: "get",
              data: { category_id: category_id },
              dataType: "json",
              success: function (result) {
                select.removeAttr("disabled");
                select.append(new Option("全部", 0));
                $.each(result.data, function (index, item) {
                  select.append(new Option(item.name, item.id));
                });
                form.render("select");
              },
            });
          } else {
            $("#matchid").attr("disabled", "disabled");
            form.render("select");
          }
        });

        form.on("submit(submitForm)", function (obj) {
          layer.confirm("确认要修改吗？", { icon: 6 }, function () {
            $.ajax({
              type: "POST", //请求方式
              url: "/admin/video/replay_edit?id={$model->id}", //请求地址
              dataType: "json", //返回的数据类型
              data: $("#sbumitForm").serialize(), //数据
              //请求成功
              success: function (data) {
                if (data.code == 0) {
                  layer.msg(data.msg, { icon: 1, time: 2000 }, function () {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    window.parent.location.reload();
                  });
                } else {
                  layer.msg(data.msg, { icon: 2, time: 5000 });
                }
              },
            });
          });
          return false;
        });
      });
    </script>
  </body>
</html>
